package com.osgc.rf.login;

import java.sql.Connection;
import java.sql.SQLException;

import com.osgc.rf.np.url.dao.DataConnect;
import com.osgc.rf.np.url.dao.Group;
import com.osgc.rf.np.url.util.model.DefaultModel;

public class LoginModel extends DefaultModel {
	
	@Override
	public void beforeInvoke() throws Exception {
		super.beforeInvoke();
		sessionHelper.removeExUser();
		setRedirect("login/login");
	}
	public void chosegroup() {
		String groupid = params.get("groupid");
		Connection con = null;
		try {
			con = DataConnect.getConnect();
			Group group = user.getGroup(groupid);
			if (group != null)
				user.setGroup(con,group);
			con.commit();
		} catch (Exception e) {
			logger.error(e.getMessage());
			if (con != null) {
				try {
					con.rollback();
				} catch (SQLException e1) {
					logger.error(e1.getMessage());
				}
			}
		}finally{
			DataConnect.close(con);
		}
		
	}

	public void removegroup() {
		user.removeGroup();		
	}

	public void logout() {
		sessionHelper.logout();
		forwradPage("login.jsp");
	}

	public void menu() {
		
	}
	@Override
	public void index() {
	}
}
